home *** CD-ROM | disk | FTP | other *** search
- Path: news.clark.net!not-for-mail
- From: gusty@clark.net (Harlan Messinger)
- Newsgroups: comp.lang.c++
- Subject: Re: What does this "const" mean?
- Date: 28 Feb 1996 22:07:52 GMT
- Organization: Clark Internet Services, Inc., Ellicott City, MD USA
- Message-ID: <4h2jno$nek@clarknet.clark.net>
- References: <4h0j7u$htp@crcnis3.unl.edu>
- NNTP-Posting-Host: explorer.clark.net
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- Chi-Jang Huang (chijang@cse.unl.edu) wrote:
- :
- : Hi,
- :
- : I have some problems regarding this program segment:
- :
- : class intset {
- : // ...
- : void start(int& i) const { i = 0; }
- : int ok(int& i) const { return i<cursize; }
- : int next(int& i) const { return x[i++]; }
- : };
-
- Each non-static member function has an implied parameter, "this". More
- fully stated, for your class the implied parameter is
-
- intset *this
-
- The "const" after the parameter list modifies this parameter, which is
- then understood to be
-
- const intset *this
-
- which, as with any function parameter, tells the compiler that the
- function is meant to be callable even if the argument provided is
- constant, which means the compiler has to check the function to make sure
- it in fact doesn't modify the argument. Nonstatic member functions that
- don't have this implied const cannot be called for objects of the class
- that were declared as const.
-
-